from core.equals import Equals
from core.match_item import MatchItem
from core.simple_equals import SimpleEquals


class NumberMatchItem(MatchItem):

    __slots__ = [
        'source',
        'target',
        'equals'
    ]

    def __init__(self, source: int, target: int, equals: Equals or None):
        self.source = source
        self.target = target
        self.equals = equals if equals is not None else SimpleEquals()

    @property
    def source_index(self):
        return self.source - 1

    @property
    def target_index(self):
        return self.target - 1

    def is_match(self, a: tuple, b: tuple) -> bool:
        return self.equals.equal(a[self.source_index], b[self.target_index])
